package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//方式1：
//@EnableConfigurationProperties(MinioProperties.class)
//方式2：
@ConfigurationPropertiesScan(basePackages = "com.atguigu.lease.common.minio")
public class MinioConfiguration {

    //映射yml配置文件中的endpoint值
//    @Value("${minio.endpoint}")
//    private String endpoint;

    //映射yml配置文件中的accessKey值
//    @Value("${minio.accessKey}")
//    private String accessKey;

    //映射yml配置文件中的secretKey值
//    @Value("${minio.secretKey}")
//    private String secretKey;

    //映射yml配置文件中的bucketName值
//    @Value("${minio.bucketName}")
//    private String bucketName;

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder().endpoint(minioProperties.getEndpoint()).credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey()).build();
    }
}
